﻿using ChiWalker.Dynamics;
using ChiWalker.Helpers;
using ChiWalker.Spell;
using ChiWalker.Utilities;
using Styx;
using Styx.TreeSharp;

namespace ChiWalker.Routines.Paladin
{
    internal class Protection
    {
        [Behavior(BehaviorType.Pull | BehaviorType.Combat)]
        [Spec(WoWSpec.PaladinProtection)]
        [Class(WoWClass.Paladin)]
        public static Composite WarriorProtection()
        {
            return
                new PrioritySelector(
                    Safers.EnsureTarget(),
                    Movement.MoveToLoS(ret => StyxWoW.Me.CurrentTarget),
                    Movement.FaceUnit(ret => StyxWoW.Me.CurrentTarget),
                    Group.BuffKings(),
                    new CastOnSelf(Spell.RighteousFury, ret => !StyxWoW.Me.HasAura("Righteous Fury")),
                    new CastOnSelf(Spell.SealofInsight, ret => !StyxWoW.Me.HasAura("Seal of Insight")),
                    new NoGCDSpell(Spell.WordofGlory, ret => StyxWoW.Me,
                        ret => StyxWoW.Me.HasAura("Bastion of Glory") && StyxWoW.Me.HealthPercent <= 70,
                        false),
                    new CastOnMyTarget(Spell.ShieldoftheRighteous,
                        ret => StyxWoW.Me.CurrentHolyPower >= 2),
                    new CastOnMyTarget(Spell.Rebuke, ret => StyxWoW.Me.CurrentTarget.CanInterruptCurrentSpellCast),
                    new CastOnSelf(Spell.LayonHands, ret => StyxWoW.Me.HealthPercent <= 30),
                    new CastOnSelf(Spell.DivineProtection, ret => StyxWoW.Me.HealthPercent <= 70),
                    new CastOnMyTarget(Spell.HammeroftheRighteous,
                        ret =>
                            Clusters.GetClusterCount(StyxWoW.Me.CurrentTarget,
                                Clusters.NearbyUnitsInCombatWithMe, ClusterType.Radius,
                                10) >= 2),
                    new CastOnMyTarget(Spell.CrusaderStrike),
                    new CastOnMyTarget(Spell.Judgment),
                    new CastOnMyTarget(Spell.AvengersShield),
                    new CastOnMyTarget(Spell.HolyWrath,
                        ret =>
                            Clusters.GetClusterCount(StyxWoW.Me, Clusters.NearbyUnitsInCombatWithMe,
                                ClusterType.Radius, 10) >= 1),
                    new CastOnMyTarget(Spell.HammerofWrath),
                    new CastOnMyTarget(Spell.Consecration,
                        ret =>
                            Clusters.GetClusterCount(StyxWoW.Me, Clusters.NearbyUnitsInCombatWithMe,
                                ClusterType.Radius, 10) >= 1),
                    Movement.MoveToUnit(ret => StyxWoW.Me.CurrentTarget)
                    );
        }
    }
}